package com.gky.gkytemplate.handler;

import com.gky.gkytemplate.common.exception.BusinessException;
import com.gky.gkytemplate.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public Result businessExceptionHandler(BusinessException e){
        log.error("程序错误码{}",e.getCode());
        log.error("程序错误信息{}",e.getMessage());
        return Result.error(e.getCode(), e.getMessage());
    }
}
